<template>
	<el-dialog :title="dialogTitle" :visible.sync="visible" width="560px" :close-on-click-modal="false">
		<el-form ref="form" :model="formData" :rules="formRules" label-width="80px" class="config_form_wrapper">
			<el-form-item label="上级领域" prop="pid">
				<sw-search-tree-select
					v-model="formData.pid"
					:tree-data="treeData"
					:default-props="defaultProps"
					placeholder="请选择上级领域"
					style="width: 100%"
				></sw-search-tree-select>
			</el-form-item>
			<el-form-item label="领域名称" prop="name">
				<el-input v-model="formData.name" placeholder="请输入领域名称"></el-input>
			</el-form-item>
			<el-form-item label="领域描述" prop="content">
				<el-input type="textarea" v-model="formData.content" placeholder="请输入领域描述"></el-input>
			</el-form-item>
			<el-form-item label="排序" prop="sort">
				<el-input-number v-model="formData.sort" controls-position="right"></el-input-number>
			</el-form-item>
		</el-form>
		<template slot="footer">
			<el-button size="medium" @click="visible = false">取消</el-button>
			<el-button size="medium" type="primary" @click="handleSubmitForm">{{ handleName }}</el-button>
		</template>
	</el-dialog>
</template>

<script>
import formMixins from '../formMixins';
export default {
	mixins: [formMixins],
	data() {
		return {
			defaultProps: {
				label: 'name',
				children: 'children'
			},
			formRules: {
				name: [{ required: true, message: '请输入领域名称', trigger: 'blur' }],
				content: [{ required: true, message: '请输入领域描述', trigger: 'blur' }],
				sort: [{ required: true, message: '请输入正整数序号', trigger: 'blur' }]
			}
		};
	},
	computed: {
		handleName() {
			if (this.addOrEdit) {
				return '新增';
			} else if (this.isAddSub) {
				return '新增';
			} else {
				return '修改';
			}
		},
		dialogTitle() {
			return `${this.handleName}研究领域`;
		},
		listData() {
			return this.$parent.principalData;
		},
		treeData() {
			let dataArr = this.$lodash.cloneDeep(this.listData);
			return [{ id: '0', name: '顶级领域', children: this.listData }];
		}
	},
	methods: {
		//格式化表单参数
		formatFormParams() {
			let params = { ...this.formData, type: this.type };
			return params;
		}
	}
};
</script>

<style lang="scss" scoped>
.config_form_wrapper {
	flex: 1;
	padding: 10px 10px 0 0;
}
</style>
